﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using SqlHelper;

namespace DXApplication1月报表
{
    public partial class XtraForm登录 : DevExpress.XtraEditors.XtraForm
    {
        public XtraForm登录()
        {
            InitializeComponent();
        }

        private void simpleButton登录_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(textEdit用户名.Text.Trim()) == true)
            {
                XtraMessageBox.Show("请输入用户名");
                return;
            }
            if (string.IsNullOrWhiteSpace(textEdit密码.Text.Trim()) == true)
            {
                XtraMessageBox.Show("请输入密码");
                return;
            }

            string sql = $"select * from [Z_用户名密码] where 用户名 = '{textEdit用户名.Text.Trim()}' and 密码 = '{textEdit密码.Text.Trim()}'";
            DataTable dt = new DataTable();
            dt = SqlHelper.SqlHelper.ExecuteDataset(sql).Tables[0];
            if (dt != null && dt.Rows.Count > 0)
            {
                //把用户名 部门存到全局变量，让其它窗体可以读到
                Program.用户名 = textEdit用户名.Text.Trim();
                Program.部门 = dt.Rows[0]["部门"].ToString();

                Form form = new XtraForm菜单();
                form.Show();
                this.Hide();
            }
            else
            {
                XtraMessageBox.Show("账号或密码错误");
            }
        }

        private void XtraForm登录_FormClosing(object sender, FormClosingEventArgs e)
        {
            //Application.Exit();
        }

        private void XtraForm登录_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

        private void simpleButton修改密码_Click(object sender, EventArgs e)
        {
            Form form = new XtraForm修改密码();
            form.ShowDialog();
        }

        private void XtraForm登录_Load(object sender, EventArgs e)
        {
            this.Text = "登录"+ Application.ProductVersion;
        }
    }
}